/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __24CE0377_34B2_40fc_8471_B10E1AF65A84__
#define __24CE0377_34B2_40fc_8471_B10E1AF65A84__

#include "../tools/head.h"

namespace xos_log
{

    class log_msg : public xos_stl::mem_item< xos::release_impl< log_msg >, thread_lock >,
		public i_log_msg
    {
    public:
        typedef xos::release_impl< log_msg > T;

    public:
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 
        static int get_xos_item_data( ITEM_DATA*& item_ptr );

    public:
        log_msg();
        ~log_msg();

    public:
        xos_box::i_list * m_pStrArgsList;
        xos_box::i_buf * m_pBuf;
        xos_box::i_string * m_pString;
        xos::i_time * m_pTime;
        f_log_destroy m_fDestroy;
        f_log_fmt_args m_fFmt;

    public:
        // 日志格式串
        const char * m_pszFmt;

        // 源码行数
        int m_nSrcCodeLine;

        // 日志级别
        int m_nLevel;

        // 模块名称和代码文件
        std::string m_file;
        std::string m_name;

        // 结果日志内容
        std::string m_log;

        // 日志时间
        int m_nMilliSecond;
        int m_nYear;
        int m_nMonth;
        int m_nDay;
        int m_nHour;
        int m_nMinute;
        int m_nSecond;

        ///////////////////////////////////////////////////////////////////////////////////////////////////
        // LogMsg method
    public:
        const char * get_log_content( char * lpszLogContent, int nCharNum, int * lpnRetCharNum );
        int get_log_time( int * lpnYear,
            int * lpnMonth, 
            int * lpnDay,
            int * lpnHour, 
            int * lpnMinute, 
            int * lpnSeconde, 
            int * lpnMilliSecond );
        int set_log_info( const char * lpszName, int ulLevel, const char * lpszCodeFile, int ulCodeLine, const char * lpszFmt );
        int set_fmt_log_fun( f_log_fmt_args & fun );
        int set_destroy_fun( f_log_destroy & fun );
        int set_fmt( const char * fmt );
        const char * get_fmt();
        xos_box::i_list * str_args_list();
        char * args_buf();

    protected:
        int init_data();
        int fmt();

    public:
        int fmt_log();
        int term();
        int init();

    };

} // xos_log

#endif // __24CE0377_34B2_40fc_8471_B10E1AF65A84__
